Skip to content

Warn when -KillTreeOnExit can't end what an exited program left running - #116

Merged
HalRiveria merged 1 commit into
mainfrom
fix/killtree-failure-warning
Dec 3, 2026
Merged

HalRiveria merged 1 commit into
mainfrom
fix/killtree-failure-warning

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

Depends on #115, merge after it.

What was wrong: once a program exits, -KillTreeOnExit ends what it left running by ending the program's own Job Object (Stop-PkExitedJobTree, through [PkChildProcessJob]::KillTree), and it threw the result away. If Windows refused to end that Job Object, nothing said so. Leftovers that held the program's output showed only as StreamTimedOut, and the others kept running unseen until they ended or PowerShell exited. They're still in the kit's own Job Object, so PowerShell exiting ends them. No cause for such a failure is known: the kit creates the Job Object with full access.

What changed: there's no fallback once the program is gone (taskkill /T finds children only through their parent), so the kit now warns, once per session, naming the process. It works like the existing warning for a program without a Job Object of its own: a ClaimKillTreeWarning in the C#, re-armed by TestResetJobWarnings. The README's -KillTreeOnExit paragraph mentions it.

A harness-only hook, PkChildProcessJob.TestFailTerminate, makes KillTree's TerminateJobObject count as refused. This changes the C#; the TypesVersion bump is in #115, which this stacks on.

How it was tested: harness section BJ runs a program that exits while a child it started holds its output, with the hook on. It does this through the batch, the dispatcher and Invoke-PkProcessWithTimeout, and checks that the child is left running with exactly one warning. A second program after that gets no second warning.

Before the change (Windows PowerShell 5.1 and PowerShell 7, the same on both):

[FAIL] and says so in one warning naming the process (0 message(s): )
[FAIL] and says so in one warning naming the process (0 message(s): )
[FAIL] and says so in one warning naming the process (0 message(s): )
[FAIL] and only once per process (0 warning(s) after a second program)

After: all pass, each with one message: [WARNING] -KillTreeOnExit couldn't stop what process N left running: Windows wouldn't end the program's own Job Object, so anything it started may still be running. It still ends when PowerShell does. Shown once. Build/Update-ParallelKitCSharp.ps1 -Compile builds the C# with no warnings under both csc.exe (C# 5) and the .NET SDK (LangVersion 5).

Full harness: all 766 assertions pass on Windows PowerShell 5.1 and on PowerShell 7.

@HalRiveria
HalRiveria added this pull request to stack #118 December 3, 2026 00:28
@HalRiveria
HalRiveria force-pushed the fix/killtree-failure-warning branch 2 times, most recently from c3d696c to 8b69970 Compare December 3, 2026 00:42
Base automatically changed from fix/rollback-exited-program to main December 3, 2026 00:53
Once a program exits, -KillTreeOnExit ends what it left running through the program's own Job Object, and discarded the result: if Windows wouldn't end that Job Object, the leftovers kept running with no sign, showing only as a stream timeout if they held the output. There is no fallback once the program is gone (taskkill /T finds children only through their parent), so it now warns, once per session, naming the process, like the warning for a program without a Job Object of its own.

A test hook, PkChildProcessJob.TestFailTerminate, makes TerminateJobObject count as refused. Harness section BJ covers the batch, the dispatcher and Invoke-PkProcessWithTimeout, and that the warning shows once. The README's -KillTreeOnExit paragraph mentions it.
@HalRiveria
HalRiveria force-pushed the fix/killtree-failure-warning branch from 8b69970 to 7325fae Compare December 3, 2026 00:53
@HalRiveria
HalRiveria merged commit 2d34e94 into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/killtree-failure-warning branch December 3, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants